package com.work04;

public class Customer extends Thread {
    private Box box;

    public Customer (Box box) {

        this.box = box;
    }

    @Override
    public void run() {
        while (true){
            synchronized (box.getObj()){
                if (box.getSum()==0){
                    break;
                }else {
                    if (!box.isXiangzi()){
                        try {
                            box.getObj().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }


                    }else {
                        System.out.println("拿了一瓶奶");
                        box.setXiangzi(false);
                        box.setSum(box.getSum()-1);
                        box.getObj().notifyAll();
                    }
                }
            }
        }
    }
}
